package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelQuestion;
import cn.wolfcode.trip.base.query.TravelQuestionQuery;
import cn.wolfcode.trip.base.service.ITravelQuestionService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("travelQuestions")
public class TravelQuestionController {
    @Autowired
    private ITravelQuestionService travelQuestionService;


    @GetMapping
    public Object list(TravelQuestionQuery qo){
        qo.setOrderBy("t.releaseTime desc");
        PageInfo pageInfo = travelQuestionService.selectForList(qo);
        return pageInfo;
    }

    @PostMapping("save")
    public JSONResult save(TravelQuestion travelQuestion) {
        JSONResult result = new JSONResult();
        try {
            travelQuestionService.save(travelQuestion);
        }catch (Exception e){
            result.mark(e.getMessage());
        }
        return result;
    }

    @GetMapping("/{state}")
    public Object list(@PathVariable int state){
        return travelQuestionService.getQuestions(state);
    }

}
